package com.psfd.demo.controller;


import com.psfd.demo.entity.ReaderInformation;
import com.psfd.demo.service.IReaderInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 *  前端控制器
 * </p>
 *读者信息
 * @author 撒旦
 * @since 2020-07-10
 */
@RestController
public class ReaderInformationController {

    @Autowired
    private IReaderInformationService readerInformationService;

    //增加
    @RequestMapping("/readerinformationinsert")
    public ModelAndView insert(ReaderInformation readerInformation){
        ModelAndView modelAndView = new ModelAndView();
        readerInformationService.save(readerInformation);
        modelAndView.addObject("readerInformationList",readerInformationService.list());
        modelAndView.setViewName("ReaderInformationQuery");
        return modelAndView;
    }

    //修改
    @RequestMapping("/readerinformationupdate")
    public ModelAndView update(ReaderInformation readerinformation){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("readerinformation",readerinformation);
        modelAndView.setViewName("ReaderInformationUpdate");
        return modelAndView;
    }

    //修改
    @RequestMapping("/readerinformationupdate1")
    public ModelAndView update1(ReaderInformation readerInformation){
        readerInformationService.updateById(readerInformation);
        return query();
    }

    //删除
    @RequestMapping("/readerinformationdelete")
    public ModelAndView delete(Integer id){
        ModelAndView modelAndView = new ModelAndView();
        readerInformationService.removeById(id);
        System.err.println("删除的ID为：" + id);
        modelAndView.addObject("readerInformationList",readerInformationService.list());
        modelAndView.setViewName("ReaderInformationQuery");
        return modelAndView;
    }

    //查询
    @RequestMapping("/readerinformationquery")
    public ModelAndView query(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("readerInformationList",readerInformationService.list());
        modelAndView.setViewName("ReaderInformationQuery");
        System.out.println(readerInformationService.list());
        return modelAndView;
    }

}

